@extends('admin.inc.base')
@section('content')
    <link rel="stylesheet" type="text/css" href="/public/statics/libs/wangEditor/dist/css/wangEditor.min.css">
    <script type="text/javascript" src="/public/statics/libs/wangEditor/dist/js/wangEditor.js"></script>
    <script type="text/javascript" src="/public/statics/libs/uploader/UploadFile.js"></script>

    <div class="panel panel-default">
        <div class="panel-heading">
            编辑文章
        </div>
        <div class="panel-body">
            <form action="/admin/post/{{ $post->id }}" method="post">
                <div class="form-group">
                    <label for="">标题</label>
                    <input type="text" class="form-control" value="{{ $post -> title }}" name="title"  placeholder="文章标题">
                </div>

                <div class="form-group">
                    <label for="">缩略图</label>
                    <div id="upload-img-show">
                        <img src="{{$post->cover}}" style="width:100px;height:100px;"/>
                    </div>
                    <span class="upload" id="upload">上传图片</span>
                    <input type="hidden" name="cover" id="upload-img" value="{{ $post->cover }}"/>
                </div>

                <div class="form-group">
                    <label for="">文章分类</label>
                    <select name="cid" class="form-control">
                        <option value="0">默认</option>
                        @foreach( $cids as $key => $val )
                            <option value="{{ $val->id }}" @if($val->id == $post->cid) selected @endif>{{ $val->title }}</option>
                        @endforeach


                    </select>
                </div>

                <div class="form-group">
                    <label for="description">摘要</label>
                    <textarea name="description" id="description" class="form-control" placeholder="摘要" style="height:100px;">{{ $post->description }}</textarea>

                    <p class="help-block">长度200，过长自动裁减</p>
                </div>

                <div class="form-group">
                    <label for="">内容</label>
                       <textarea name="content" id="content" class="form-control" style="height:400px;">
                            {{ $post -> content }}
                       </textarea>

                    <p class="help-block"></p>
                </div>

                <button type="submit" class="btn btn-default">提交</button>
            </form>
        </div>
    </div>

    <script type="text/javascript">
        var editor = new wangEditor('content');
        editor.create();
    </script>

    <script type="text/javascript">
        var upload = new Upload({
            "clickDom":"upload",
            "action":"/admin/upload",
            "onUploadSuccess":function(data){
                if(data.status == 'ok'){
                    $('#upload-img').val(data.url);
                    $("#upload-img-show").html('<img src="'+data.url+'" style="width:100px;height:100px;"/>');
                }else{
                    console.log(data);
                }
            }
        });
    </script>
@endsection